export default {
  namespaced:true,
  actions: {
    // (5) 将业务逻辑都写在actions里面，没有业务逻辑的就直接在组件里commit
    addOdd(context, value) {
      if (context.state.sum % 2) {
        context.commit("AddOdd", value);
      }
    },

    addWait(context, value) {
      setTimeout(() => {
        context.commit("AddWait", value);
      }, 500);
    },
  },
  mutations: {
    // (4) state 用来获取并操作里面的数据
    Add(state, value) {
      //  console.log('mutations里面的Add被调用了',state,value);
      state.sum += value;
    },

    Sub(state, value) {
      state.sum -= value;
    },

    AddOdd(state, value) {
      state.sum += value;
    },

    AddWait(state, value) {
      state.sum += value;
    },
  },
  state: {
    sum: 0,
    school: "尚硅谷",
    subject: "前端",
  },
  getters: {
    bigSum(state) {
      return state.sum * 10;
    },
  },
};
